package  com.sat.common.utils

import com.google.gson.Gson
import com.google.gson.GsonBuilder
import java.lang.reflect.Type

object GsonUtils {
    var mGson: Gson? = null
    val gson: Gson?
        get() {
            if (mGson == null) {
                mGson = GsonBuilder().create()
            }
            return mGson
        }

    fun toJson(src: Any?): String {
        return gson!!.toJson(src)
    }

    fun <T> fromJson(json: String?, classOfT: Class<T>?): T {
        return gson!!.fromJson(json, classOfT)
    }

    fun <T> fromJson(json: String?, typeOfT: Type?): T {
        return gson!!.fromJson(json, typeOfT)
    }
}
